package com.mall.enums;

import lombok.Getter;

@Getter
public enum RoleEnum {
    USER(1L, "普通用户", "user"),
    MERCHANT(2L, "商家", "merchant"),
    ADMIN(3L, "管理员", "admin");

    private final Long roleId;
    private final String roleName;
    private final String roleKey;

    RoleEnum(Long roleId, String roleName, String roleKey) {
        this.roleId = roleId;
        this.roleName = roleName;
        this.roleKey = roleKey;
    }

    // 根据 roleId 获取枚举实例
    public static RoleEnum getByRoleId(Long roleId) {
        for (RoleEnum role : values()) {
            if (role.getRoleId().equals(roleId)) {
                return role;
            }
        }
        return null;
    }

    // 根据 roleKey 获取枚举实例
    public static RoleEnum getByRoleKey(String roleKey) {
        for (RoleEnum role : values()) {
            if (role.getRoleKey().equals(roleKey)) {
                return role;
            }
        }
        return null;
    }
}

